package simulation;

/**
 * 路径类。存放两个空间startSpace， endSpace和时间片长度timeSlice，以及要在多少个counter内走完
 */
public class Path {
    private int startSpace;
    private int endSpace;
    private int timeSlice;
    private int count;

    public int getStartSpace() {
        return startSpace;
    }

    public int getEndSpace() {
        return endSpace;
    }
    public int getTimeSlice() {
        return timeSlice;
    }

    public void setStartSpace(int startSpace) {
        this.startSpace = startSpace;
    }

    public void setEndSpace(int endSpace) {
        this.endSpace = endSpace;
    }

    public int getCountStart() {
        if(startSpace == endSpace) return count;
        if(startSpace == 19) return 0; // 19表示操场space
        if(endSpace == 19) return count;
        Space start = Map.getSpaces().get(startSpace);
        double sizeofSpace = (start.getDown() - start.getUp() +start.getRight() - start.getLeft()) / 2;
        Position startDoor = Map.getSpaces().get(startSpace).getDoor().getRandomPos();
        Position endDoor = Map.getSpaces().get(endSpace).getDoor().getRandomPos();
        double sizeBetweenDoors = Math.abs(startDoor.getX() - endDoor.getY()) +
                Math.abs(startDoor.getY() - endDoor.getY());
        int ret = (int)(count * (sizeofSpace / (sizeofSpace + sizeBetweenDoors)));
        if (ret == 0)
            ret++;
        return ret;
    }

    public int getCountGround() {
        return count - getCountStart();
    }

    public void setTimeSlice(int timeSlice) {
        this.count = timeSlice;
        this.timeSlice = timeSlice;
    }

    public Path(int startSpace, int endSpace) {
        this.startSpace = startSpace;
        this.endSpace = endSpace;
    }
    public Path(int startSpace, int endSpace,int timeSlice) {
        this.startSpace = startSpace;
        this.endSpace = endSpace;
        this.count = timeSlice;
        this.timeSlice = timeSlice;
    }

    @Override
    protected Path clone() {
        return new Path(this.startSpace, this.endSpace);
    }
}


